package com.chinalife.project.service.impl;

import com.chinalife.project.entity.DailyInfo;
import com.chinalife.project.dao.DailyInfoDao;
import com.chinalife.project.service.DailyInfoService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 每日处罚信息(DailyInfo)表服务实现类
 *
 * @author makejava
 * @since 2024-07-18 15:06:57
 */
@Service("dailyInfoService")
public class DailyInfoServiceImpl implements DailyInfoService {

    private final DailyInfoDao dailyInfoDao;
    public DailyInfoServiceImpl(DailyInfoDao dailyInfoDao) {
        this.dailyInfoDao = dailyInfoDao;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public DailyInfo queryById(Long id) {
        return this.dailyInfoDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param dailyInfo   筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<DailyInfo> queryByPage(DailyInfo dailyInfo, PageRequest pageRequest) {
        long total = this.dailyInfoDao.count(dailyInfo);
        return new PageImpl<>(this.dailyInfoDao.queryAllByLimit(dailyInfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param dailyInfo 实例对象
     * @return 实例对象
     */
    @Override
    public DailyInfo insert(DailyInfo dailyInfo) {
        this.dailyInfoDao.insert(dailyInfo);
        return dailyInfo;
    }

    /**
     * 修改数据
     *
     * @param dailyInfo 实例对象
     * @return 实例对象
     */
    @Override
    public DailyInfo update(DailyInfo dailyInfo) {
        this.dailyInfoDao.update(dailyInfo);
        return this.queryById(dailyInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.dailyInfoDao.deleteById(id) > 0;
    }
}
